package com.varian.system.listener;

import com.varian.redis.util.RedisUtil;
import com.varian.system.constant.SystemConstant;
import com.varian.system.service.ISysNoticeService;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author ben
 * @since 2024/9/3
 */
@Component
@RequiredArgsConstructor
public class SysNoticeListener {

    private final ISysNoticeService noticeService;

    @RabbitListener(queues = SystemConstant.QUEUE_NOTICE_SEND)
    public void noticeSend(Long id) {
        RedisUtil.lock(SystemConstant.KEY_LOCK_NOTICE_SEND.format(id), () -> noticeService.processListenerNoticeSend(id));
    }

    @RabbitListener(queues = SystemConstant.QUEUE_NOTICE_EXPIRE)
    public void noticeExpire(Long id) {
        RedisUtil.lock(SystemConstant.KEY_LOCK_NOTICE_EXPIRE.format(id), () -> noticeService.processListenerNoticeExpire(id));
    }
}
